/**
 * @file Sphere.cc
 *
 * @author Tomasz Rudny (rudnyt@gmail.com)
 * @brief Visualization of a sphere. Provides methods for rendering a freely
 * orientated sphere.
 *
 * @version 1.0
 */

#include "Sphere.h"

using namespace graph;

/**
 * Constructor
 *
 */
Sphere::Sphere() {
	r = 0.2f;
	colour[0] = 0.3f;
	colour[1] = 0.7f;
	colour[2] = 0.9f;
}

/**
 * Constructor
 * @param _r radius of the sphere
 *
 */
Sphere::Sphere(double _r) :
	r((float)_r) {
	colour[0] = 0.3f;
	colour[1] = 0.7f;
	colour[2] = 0.9f;
}

void Sphere::draw(const GLfloat m[]) {

}

void Sphere::draw(const RSIM::Transform& tm) {
	// convert RSIM::Transform into GLfloat matrix
	const double *R = tm.R().Ptr(), *P = tm.P().Ptr();
	GLfloat m[] = { (GLfloat)R[0], (GLfloat)R[3], (GLfloat)R[6], 0.0f,
			(GLfloat)R[1], (GLfloat)R[4], (GLfloat)R[7], 0.0f, (GLfloat)R[2],
			(GLfloat)R[5], (GLfloat)R[8], 0.0f, (GLfloat)P[0], (GLfloat)P[1],
			(GLfloat)P[2], 1.0f };

	GLUquadricObj* qObj = gluNewQuadric();
	glColor3d(colour[0], colour[1], colour[2]);
	glPushMatrix();
	glMultMatrixf(m);
	glRotatef(90, 0.0f, 1.0f, 0.0f);

	gluSphere(qObj, r, 20, 20);
	glPopMatrix();
	gluDeleteQuadric(qObj);
}
